
package com.gwtplatform.samples.hplace.client.home;

import com.google.inject.Inject;

import com.guit.client.GuitPresenter;
import com.guit.client.binder.GuitBinder;
import com.guit.client.binder.ViewHandler;
import com.guit.client.place.Place;
import com.gwtplatform.samples.hplace.client.breadcrumbs.Backeable;
import com.gwtplatform.samples.hplace.client.breadcrumbs.BreadcrumbsPresenter;
import com.gwtplatform.samples.hplace.client.home.HomePresenter.HomeBinder;
import com.gwtplatform.samples.hplace.client.productlist.ProductListPresenter;
import com.gwtplatform.samples.hplace.shared.Product;

import java.util.ArrayList;

public class HomePresenter extends GuitPresenter<HomeBinder> implements Place<Void> {
    
    private static final String HOME = "home";
    private final ArrayList<String> names = new ArrayList<String>();

    public static interface HomeBinder extends GuitBinder<HomePresenter> {
    }

    @Inject
    public HomePresenter(BreadcrumbsPresenter breadcrumbsPresenter) {
        this.breadcrumbsPresenter = breadcrumbsPresenter;
        names.add(HOME);
    }
    
    BreadcrumbsPresenter breadcrumbsPresenter;
    
    @ViewHandler
    protected void all$click() {
        placeManager.go(ProductListPresenter.class, new Backeable<Integer>(0, getTokens() , names));
    }

    private ArrayList<String> getTokens() {
        ArrayList<String> tokens = new ArrayList<String>();
        tokens.add(placeManager.getCurrentToken());
        return tokens;
    }
    
    @ViewHandler
    protected void favorites$click() {
        placeManager.go(ProductListPresenter.class, new Backeable<Integer>(Product.FLAG_FAVORITE, getTokens() , names));
    }
    
    @ViewHandler
    protected void specials$click() {
        placeManager.go(ProductListPresenter.class, new Backeable<Integer>(Product.FLAG_SPECIAL, getTokens() , names));
    }
    
    @Override
    public void go(Void data) {
        breadcrumbsPresenter.buildNavegation(HOME, getView(), null);
    }
}